# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=distorm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.5.2
pkgrel=4
pkgdesc="Powerful disassembler library for x86/AMD64 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://github.com/gdabah/distorm"
license=('GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/gdabah/distorm/archive/${pkgver}.tar.gz
        Makefile)
sha256sums=('ef858f430d16156dea2edc910750cabf2a21154b24cfa7edf714a8ea8799f1d9'
            '35ef18fd815abe1b03b7b264ae517cd8d1564665cb5a34604b0b624ac820a4c4')

prepare() {
  cd ${_realname}-${pkgver}
  cp -f ${srcdir}/Makefile make/win32/
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  make -C make/win32
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}

  make -C make/win32 DESTDIR="${pkgdir}" INSTALL_PREFIX=${MINGW_PREFIX} install

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --skip-build -O1

  install -Dm 644 include/*.h -t "${pkgdir}${MINGW_PREFIX}/include"
  install -Dm 644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
